package com.aloda.controller.common;

import com.aloda.dto.PhoneCodeDTO;
import com.aloda.result.Result;
import com.aloda.service.VerifyService;
import com.aloda.vo.VerifyVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Slf4j
@RestController
@Tag(name = "通用接口")
@RequestMapping("/common")
public class VerifyController {

    @Resource
    private VerifyService verifyService;

    /**
     * 获取图形验证码
     * @param request
     * @return
     * @throws IOException
     */
    @Operation(summary = "获取图形验证码")
    @GetMapping("/verify")
    public Result<VerifyVO> getCode(HttpServletRequest request) throws IOException {
        VerifyVO verifyVO = verifyService.getImgCode(request);
        return Result.success("验证码获取成功",verifyVO);
    }

    /**
     * 获取手机号验证码
     * @return
     */
    @Operation(summary = "获取手机号验证码")
    @PostMapping("/code")
    public Result getPhoneCode(@RequestBody PhoneCodeDTO phoneCodeDTO) {
        verifyService.getPhoneCode(phoneCodeDTO);
        return Result.success("发送成功");
    }
}
